'use strict';

/**
 * @ngdoc function
 * @name webApp.controller:ResetpasswordCtrl
 * @description
 * # ResetpasswordCtrl
 * Controller of the webApp
 */
angular.module('webApp')
  .controller('ResetpasswordCtrl', function ($scope,$ionicScrollDelegate,jqLite,promiseResetPassword,popBox,$location) {
    $scope.$on('$stateChangeSuccess',function(){
      //参数查询
      if(!$location.search()['confirmation'] && $location.$$path == '/root/resetPassword'){
        popBox.showConfirm('警告','无效的页面路由请求！');
        $location.path('/root/home');
      }
      else if($location.search()['confirmation'] && $location.$$path != '/root/resetPassword'){
        $location.search('confirmation',null);
      }
      $scope.user = [];
      //修改密码
      $scope.submit = function(){
        if(!$scope.user.password || !$scope.user.password_confirmation){
          popBox.showConfirm('警告','密码不能为空！');
        }
        else{
          if($scope.user.password == $scope.user.password_confirmation){
            promiseResetPassword.resetPassword($scope.user.password,$scope.user.password_confirmation,$location.search()['confirmation']).then(function(){
              popBox.showConfirm('提示','成功修改密码！');
              $location.path('/root/signIn');
            },function(){
              $location.path('/root/forgetPassword');
            });
          }
          else{
            popBox.showConfirm('警告','两次输入密码不同！');
          }
        }
      };
    });
  });
